package com.it.day1;

import java.util.concurrent.FutureTask;

/**
 * ClassName: FutureDemo
 * Description: FutureTask创建线程
 *
 * @Author: csx
 * @Create: 2025/5/7 - 23:25
 * @version: v1.0
 */
public class FutureTaskDemo {
    public static void main(String[] args) throws Exception {
        FutureTask<String> task = new FutureTask<>(() -> {
            System.out.println(Thread.currentThread().getName() + "\t" + "执行了");
            Thread.sleep(5000);
            return "老师我帮你买到水了";
        });
        new Thread(task).start();

        System.out.println(task.get());
//        System.out.println(task.get(2, TimeUnit.SECONDS));

        System.out.println("继续上课");
    }
}
